package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Department;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import cn.wolfcode.util.RequirePermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    //部门页面的增删改查

    //查
    @RequirePermission(name = "部门页面",expression = "department:list")
    @RequestMapping("/list")
    public String query(QueryObject qo, Model model){
        PageInfo<Department> pageInfo = departmentService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        //返回的JSP视图
        return "department/list";
    }

    //删
    @RequirePermission(name = "部门删除",expression = "department:delete")
    @RequestMapping("/delete")
    public String delete(Long id){
        departmentService.delete(id);
        //重定向会原来的list页面
        return "redirect:/department/list";
    }

    //增改
    @RequirePermission(name = "部门新增/编辑",expression = "department:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Department department){
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list";
    }
}
